//
//  commentModel.m
//  百思不得姐comment
//
//  Created by 韦宗华 on 16/8/29.
//  Copyright © 2016年 joinWei. All rights reserved.
//

#import "commentModel.h"
#import "AFHTTPSessionManager.h"
#import "userModel.h"
@implementation commentModel

+(instancetype)commentWithDic:(NSDictionary *)dic
{
    commentModel* model = [[commentModel alloc]init];
    [model setValuesForKeysWithDictionary:dic];
    return model;
}
-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}

+(void)downloadWithUrlstring:(NSString *)urlString successBlock:(void (^)(NSArray *arr,NSArray*hotArr))successBlock failBlock:(void (^)(NSError *error))failBlock
{
    AFHTTPSessionManager* manager = [[AFHTTPSessionManager alloc]init];
    [manager GET:urlString parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSArray* dataArr = responseObject[@"data"];
        NSArray* HotArr = responseObject[@"hot"];
        NSMutableArray* dataM = [[NSMutableArray alloc]init];
        NSMutableArray* hotM = [[NSMutableArray alloc]init];
        [dataArr enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL * _Nonnull stop) {
            commentModel* model = [commentModel commentWithDic:obj];
            [dataM addObject:model];
        }];
        [HotArr enumerateObjectsUsingBlock:^(NSDictionary* obj, NSUInteger idx, BOOL * _Nonnull stop) {
            commentModel* model = [commentModel commentWithDic:obj];
            [hotM addObject:model];
        }];
        if (successBlock) {
            successBlock(dataM,hotM);
        }
        
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (failBlock) {
            failBlock(error);
        }
    }];
    
    
    
    
    
    
    
    
    
    
    
    
}



@end
